package org.mili.ticketeer.dto;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

public class Action extends Identifieable implements Archivable {

    public static enum Fields implements Field {
        TICKET,
        DATE,
        TITLE,
        COMMENT;
    }

    public static enum UniqueFields implements Field {
        TICKET,
        DATE,
        TITLE;
    }

    public static final String TABLE = "action";

    private int ticket;
    private Timestamp date;
    private String title;
    private String comment;

    @Override
    public Map<Field, Object> valueMap() {
        Map<Field, Object> map = super.valueMap();
        map.put(Fields.TICKET, ticket);
        map.put(Fields.DATE, date);
        map.put(Fields.TITLE, title);
        map.put(Fields.COMMENT, comment);
        return map;
    }

    @Override
    public Map<Field, Object> valueMapWithoutId() {
        Map<Field, Object> map = new HashMap<>(valueMap());
        map.remove(Identifieable.Fields.ID);
        return map;
    }

    @Override
    public Map<Field, Object> getUniqueFields() {
        Map<Field, Object> map = new HashMap<>();
        map.put(Fields.TICKET, ticket);
        map.put(Fields.TITLE, title);
        map.put(Fields.DATE, date);
        return map;
    }

    public int getTicket() {
        return ticket;
    }

    public void setTicket(int ticket) {
        this.ticket = ticket;
    }

    public Timestamp getDate() {
        return date;
    }

    public void setDate(Timestamp date) {
        this.date = date;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Action action = (Action) o;

        if (ticket != action.ticket) return false;
        if (comment != null ? !comment.equals(action.comment) : action.comment != null) return false;
        if (date != null ? !date.equals(action.date) : action.date != null) return false;
        if (title != null ? !title.equals(action.title) : action.title != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = ticket;
        result = 31 * result + (date != null ? date.hashCode() : 0);
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (comment != null ? comment.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Action{" +
                "ticket=" + ticket +
                ", date=" + date +
                ", title='" + title + '\'' +
                ", comment='" + comment + '\'' +
                '}';
    }
}
